﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Collections.Generic;
using COM.OA.Entity;
using COM.OA.BLL;

public partial class qs_wenjian_jiqunchuansong : System.Web.UI.Page
{
   
protected void Page_Load(object sender, EventArgs e)
    {
       
    }
    //部门连动出员工
    protected void ddl_bumen_SelectedIndexChanged(object sender, EventArgs e)
    {
        String bumen = this.ddl_bumen.Text;

        // String where = "em_dept_id='{0}'";
        //  where = string.Format(where,bumen);
        //   IList<employee> list = employeeBLL.Select(where);


        SqlParameter parambumen = new SqlParameter("@deptid", bumen);
        IList<liandongrenqs> lists = BLLGeneric.Select<liandongrenqs>(CommandType.StoredProcedure, "liandongqs", parambumen);
        this.ddl_duixiang.DataSource = lists;
        this.ddl_duixiang.DataTextField = "u_username";
        this.ddl_duixiang.DataValueField = "u_username";
        //this.ddl_duixiang.DataValueField = "Em_id";
        this.ddl_duixiang.DataBind();
    }
    //清除
    protected void Button4_Click(object sender, EventArgs e)
    {
        this.txt_jieshouren.Text = "";
    }
    //增加按钮
    protected void Button1_Click(object sender, EventArgs e)
    {

        string duixiang = this.ddl_duixiang.Text;

        this.txt_jieshouren.Text = duixiang;
    }

    protected void btQingKong_Click(object sender, EventArgs e)
    {
        this.ddl_bumen.Text = "0";
        this.ddl_duixiang.Text = "0";
      
        this.txt_jieshouren.Text = "";
      
        

    }
    protected void btChuanZiJi_Click(object sender, EventArgs e)
    {
        //当前登陆人
        users loginuser = Session["loginuser"] as users;
        if (loginuser == null)
        {
            this.Response.Write(string.Format(GetRedirect.REDIRECT, "../login.aspx"));
        }
        else
        {

            int bumenid = loginuser.u_dept_id;
            string bumenId = bumenid.ToString();

            string myname = loginuser.u_username;
            this.txt_jieshouren.Text = myname;
            this.ddl_bumen.Text = bumenId;
            
            
        }
    }
    protected void btFaSong_Click(object sender, EventArgs e)
    {
        //登陆人的名字转成ID
        users loginuser = Session["loginuser"] as users;
        if (loginuser == null)
        {
            this.Response.Write(string.Format(GetRedirect.REDIRECT, "../login.aspx"));
        }
        else
        {
            int userId = loginuser.u_id;

            //string fasongren = "haha";
            //string where1 = "u_username='{0}'";
            //where1 = string.Format(where1, fasongren);
            //IList<users> listuname = usersBLL.Select(where1);
            //users user = listuname[0];
            //int userId = user.u_id;


            //取部门ID
            
            int bumenid =Int32.Parse( this.ddl_bumen.Text);



            //取上传文件名
            string name = this.fluWenJian.FileName;

            int startIndex = this.fluWenJian.FileName.LastIndexOf(@"\") + 1;
            string fileName = this.fluWenJian.FileName.Substring(startIndex);
            string phyFileName = this.Server.MapPath(@"..\gxxz\" + "upload") + @"\" + fileName;
            this.fluWenJian.SaveAs(phyFileName);

            //取接收人姓名转成ID封装
            string jieshourenming = this.txt_jieshouren.Text;
            string where2 = "u_username='{0}'";
            where2 = string.Format(where2, jieshourenming);
            IList<users> listuname2 = usersBLL.Select(where2);
            users users = listuname2[0];
            int userId2 = users.u_id;


            DateTime fsendtiem = DateTime.Now;


            files fs = new files();
            fs.f_filename = name;
            //所有默认归纳为其他类别
            fs.f_ftype_id = 1;
            fs.f_dept_id = bumenid;
            //发送人id
            fs.f_sendu_id = userId;
            //接收人id
            fs.f_takeu_id = userId2;
            //是否共享 0为否1为是
            fs.f_isshare = 0;
            //备注
            //fs.f_remark = "";
            //是否回执0为否1为是
            fs.f_isreturn = 0;
            //读否
            fs.f_isread = 0;
            //阅读次数
            fs.f_readdegree = 0;
            //阅读时间
            fs.f_releasetime = DateTime.Now;
            //状态 
            fs.f_state = 0;

            filesBLL.Insert(fs);
            this.Response.Write(string.Format(GetRedirect.WINALERT, "发送成功"));


        }
    }
    
}
